package cn.wolfcode.rbac.service.impl;

import cn.wolfcode.rbac.domain.CustomerTransfer;
import cn.wolfcode.rbac.mapper.CustomerMapper;
import cn.wolfcode.rbac.mapper.CustomerTransferMapper;
import cn.wolfcode.rbac.query.CustomerTransferQueryObject;
import cn.wolfcode.rbac.service.ICustomerTransferService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class CustomerTransferServiceImpl implements ICustomerTransferService {
    @Autowired
    private CustomerTransferMapper mapper;
    @Autowired
    private CustomerMapper customerMapper;
    public void saveOrUpdate(CustomerTransfer u) {
        if(u.getId()==null){
            customerMapper.updateSeller(u.getNewseller().getId(),u.getCustomer().getId());
            mapper.insert(u);
        }else{
            mapper.updateByPrimaryKey(u);
        }
    }


    public void delete(Long id) {
        mapper.deleteByPrimaryKey(id);
    }


    public PageInfo query(CustomerTransferQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<CustomerTransfer> result = mapper.queryForList(qo);
        return new PageInfo(result);
    }


    public CustomerTransfer selectOne(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    public List<CustomerTransfer> listAll() {
        return mapper.selectAll();
    }


}
